﻿using hyjx;
using hyjx.bind;
using GanFengLogViewer.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
using System.Threading;

namespace GanFengLogViewer.Commands
{
    public class FilterCommand : CommandBase
    {
        public override bool CanExecute(object? parameter)
        {
            MainWindowViewModel? vm = (MainWindowViewModel?)parameter;
            if (vm == null)
                return false;

            return vm.IsIdle;
        }

        public override void Execute(object? parameter)
        {
            if (!CanExecute(parameter))
                return;

            MainWindowViewModel? vm = (MainWindowViewModel?)parameter;
            if(vm == null) 
                return;

            vm.Pagor.CurrentPageNumber = 1;
            if (vm.Filter.EndDate != null)
            {
                DateTime now = DateTime.Now;
                if (vm.Filter.EndDate.Value.Date == now.Date)
                    vm.Filter.EndDate = now;
            }
            vm.GetLogs();
        }
    }
}
